package com.zhaorui.enablescheduling;

import com.zhaorui.entity.GzMfJh;
import com.zhaorui.entity.GzTfJh;
import com.zhaorui.mapper.GzMfJhMapper;
import com.zhaorui.mapper.GzTfJhMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 静态执行
 */
@Configuration //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@Slf4j
public class SimpleScheduleConfig5 {
    @Autowired
    private GzTfJhMapper gzTfJhMapper;

    //3.添加定时任务
//    @Scheduled(cron = "0 */1 * * * ?")
    @Scheduled(cron = "*/35 * * * * ?")

    /**
     * TF_JH
     */
    private void configureTasks() {
        System.err.println("执行Tf_jh--Gz_Tf_jh定时任务: " + LocalDateTime.now().toLocalTime());
        //查询新增订单
        List<GzTfJh> gzTfJhList = gzTfJhMapper.queryDiffAll();
        if (gzTfJhList.size() == 0) {
            log.info("暂无数据");
            return;
        }
        //循环插入表身
        for (int i = 0; i < gzTfJhList.size(); i++) {
            GzTfJh gzTfJh = gzTfJhList.get(i);
            gzTfJhMapper.insertByJhNo(gzTfJh);
        }
        log.info("插入GZ_TF_JH,{},数据，插入的数据是：{}", gzTfJhList.size(), gzTfJhList);
    }
}